package com.crhms.seabow.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.crhms.seabow.entity.Subtitle;
import com.crhms.seabow.repository.LessonRepository;
import com.crhms.seabow.repository.SubtitleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SubtitleService {

    @Autowired
    private SubtitleRepository subtitleRepository;

    @Autowired
    private LessonService lessonService;

    public List<Subtitle> getSubtitle(String lessonId,Integer category) {

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("lesson_id",lessonId);
        // wrapper.eq("category",category);
        List<Subtitle> subtitles = subtitleRepository.selectList(wrapper);

        return  subtitles;
    }

    public boolean saveSubtitles(int lessonId, List<String> sentences) {

        sentences.forEach(m->{
            if (!StringUtils.isEmpty(m)) {
                if (m.contains("第")) {
                    lessonService.saveLesson(lessonId, m);
                }
                Subtitle subtitle = new Subtitle();
                subtitle.setLessonId(lessonId);
                subtitle.setContent(m);
                subtitleRepository.insert(subtitle);
            }
        });
        return true;
    }
}
